class Idris2 < Formula
  desc "Pure functional programming language with dependent types"
  homepage "https://www.idris-lang.org/"
  url "https://github.com/idris-lang/Idris2/archive/v0.3.0.tar.gz"
  sha256 "2b1a921c3b46eec629936579a93319b2adb1c66a61302cd5f0b53017a07b1b74"
  license "BSD-3-Clause"
  head "https://github.com/idris-lang/Idris2.git"

  bottle do
    rebuild 2
    sha256 cellar: :any, big_sur:  "1e4218062d2a87d3853f8da8e599758e190f03be1d0604beab704be8c7371799"
    sha256 cellar: :any, catalina: "5e16de326bedfd62125df1aba90c23a6dda787de249b87c7956c92723ab14e79"
    sha256 cellar: :any, mojave:   "665843c6266b26615af0b5792684f53b217116c83aff310ff36f538e837f070f"
  end

  depends_on "chezscheme"
  depends_on "coreutils"

  def install
    ENV.deparallelize
    scheme = Formula["chezscheme"].bin/"chez"
    system "make", "bootstrap", "SCHEME=#{scheme}", "PREFIX=#{libexec}"
    system "make", "install", "PREFIX=#{libexec}"
    # idris2.so is an executable file generated by Idris2
    bin.install "#{libexec}/bin/idris2_app/idris2.so" => "idris2"
    lib.install_symlink Dir["#{libexec}/lib/#{shared_library("*")}"]
  end

  test do
    (testpath/"hello.idr").write <<~EOS
      module Main
      main : IO ()
      main = putStrLn "Hello, Homebrew!"
    EOS

    system bin/"idris2", "hello.idr", "-o", "hello"
    assert_equal "Hello, Homebrew!",
                 shell_output("./build/exec/hello_app/hello.so").chomp
  end
end
